package addCompo.button
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	
	/**
	 * <br> 클래스 설명 : </br>
	 * @author 강석민
	 */	
	public class XMButton extends MovieClip
	{
		//-----------------------------------------------------------------------------------
		// public vars
		//-----------------------------------------------------------------------------------
		public var bg : MovieClip;
		//-----------------------------------------------------------------------------------
		// protected / internal vars
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// private vars
		//-----------------------------------------------------------------------------------
		private var labelTF : TextField = new TextField();
		//-----------------------------------------------------------------------------------
		// public functions
		//-----------------------------------------------------------------------------------
		
		/**
		 * constructor 
		 */	
		public function XMButton()
		{
			super();
			this.bg.stop();
			
			var tf : TextFormat = new TextFormat( "돋움", 12, 0x666666, true );
			labelTF.defaultTextFormat = tf;
			labelTF.autoSize = TextFieldAutoSize.LEFT;
			labelTF.selectable = false;
			labelTF.mouseEnabled = false;
			this.addChild( labelTF);
			labelTF.text = "Button";
			
			tfPositioning();
			
			this.addEventListener(MouseEvent.MOUSE_DOWN, onBtnDown );
			this.addEventListener(MouseEvent.CLICK , onBtnClick );
			this.addEventListener(MouseEvent.MOUSE_UP, onBtnUp );
			this.addEventListener(MouseEvent.MOUSE_OUT, onBtnUp );
			
		}
		
		
		
		[Inspectable(name="ButtonHeight", defaultValue = "50", type = Number )]
		public function set ButtonHeight ( value : Number ):void
		{
			this.bg.height = Number(value);
		}
		
		[Inspectable(name="ButtonWidth", defaultValue = "100", type = Number )]
		public function set ButtonWidth ( value : Number ):void
		{
			this.bg.width = Number(value);
		}
		
		[Inspectable(name="Label", defaultValue = "Button", type = String )]
		public function get Label ():String
		{
			return labelTF.text;
		}
		public function set Label ( str : String ):void
		{
			labelTF.text = str;
			tfPositioning();
		}
		
		[Inspectable(name="LabelColor", defaultValue="#666666", type=Color )]
		public function set LabelColor ( value : Number ):void
		{
			var tf : TextFormat = new TextFormat();
			tf.color = value;
			labelTF.setTextFormat( tf );
			tfPositioning();
		}
		
		[Inspectable(name="LabelSize", defaultValue="12", type=Number )]
		public function set LabelSize ( value : Number ):void
		{
			var tf : TextFormat = new TextFormat();
			tf.size = int(value);
			
			labelTF.setTextFormat( tf );
			tfPositioning();
		}
		
		//-----------------------------------------------------------------------------------
		// setter / getter
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// protected functions
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// internal functions
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// private functions
		//-----------------------------------------------------------------------------------
		/**
		 *
		 */
		private function tfPositioning():void
		{
			labelTF.x = (this.width - labelTF.width)/2;
			labelTF.y = (this.height - labelTF.height)/2;
		}
		
		//-----------------------------------------------------------------------------------
		// event handler
		//-----------------------------------------------------------------------------------
		/**
		 *
		 */
		private function onBtnUp(e:MouseEvent):void
		{
			var currentTarget : MovieClip = e.currentTarget as MovieClip;
			currentTarget.bg.gotoAndStop( 1 );
		}
		
		/**
		 *
		 */
		private function onBtnDown(e:MouseEvent):void
		{
			var currentTarget : MovieClip = e.currentTarget as MovieClip;
			currentTarget.bg.gotoAndStop( 2 );
			
		}
		
		/**
		 *
		 */
		private function onBtnClick(e:MouseEvent):void
		{
		}
		
		
	}
}